//
// Created by f12160c on 2018/7/26.
//

#include <iostream>
#include <vector>
#include <unordered_map>
#include <unordered_set>
#include <algorithm>

#include "leetcode/leetcode.hpp"

using namespace std;

ListNode* Solution::swapPairs(ListNode* head)
{
    ListNode *tmp, *curr, *next;
    if(head == nullptr || head->next == nullptr){
        return head;
    }
    curr = head;
    next = curr->next;
    curr->next = next->next;
    next->next = curr;
    head = next;

    next = curr->next;


    while(next && next->next){
        tmp = curr;
        curr = next;
        next = next->next;

        curr->next = next->next;
        next->next = curr;
        tmp->next = next;

        next = curr->next;
    }

    return head;
}
